﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace SpaceInvaders
{
    class Player
    {
        Rectangle colision;
        Texture2D texture;
        KeyboardState tecladoAtual, tecladoAnterior;
        Shot shot;

        public Player(Rectangle colision)
        {
            this.colision = colision;
            shot = new Shot(new Rectangle(colision.Width/2, colision.Y, 10, 10));
        }
        
        public void Load(ContentManager Content)
        {
            texture = Content.Load<Texture2D>("nave");
            shot.Load(Content);
        }

        public void Update(GameTime gameTime)
        {
            tecladoAtual = Keyboard.GetState();

            #region MOVIMENTAÇÃO DA NAVE

            if (tecladoAtual.IsKeyDown(Keys.Right))
            {
                colision.X+=5;
            }
            if (tecladoAtual.IsKeyDown(Keys.Left))
            {
                colision.X-=5;
            }

            #endregion

            #region COLISÃO DA NAVE COM A TELA

            if (colision.X > 800 - colision.Width)
            {
                colision.X = 800-colision.Width ;
            }
            if (colision.X < 0)
            {
                colision.X = 0;
            }

            #endregion 

            if (tecladoAtual.IsKeyDown(Keys.Z))
                shot.Update(gameTime);

            tecladoAnterior = tecladoAtual;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, colision, Color.White);

            if (tecladoAtual.IsKeyDown(Keys.Z))
            shot.Draw(spriteBatch);
        }
    }

   }
